package com.example.orderminiappapi.tool;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class GetMode {

    public String listGetMode(List<String> l) {
        String regex;
        Pattern p;
        Matcher m;
        String tmp = "";
        String tot_str = l.toString();

        int max_cnt = 0;
        String max_str = "";
        for(String str : l) {
            if (tmp.equals(str)) continue;
            tmp = str;
            regex = str;
            p = Pattern.compile(regex);
            m = p.matcher(tot_str);
            int cnt = 0;
            while(m.find()) {
                cnt++;
            }
            //System.out.println(str + ":" + cnt);
            if (cnt > max_cnt) {
                max_cnt = cnt;
                max_str = str;
            }
        }

        return max_str;
    }
}
